<?php
require_once('include/permiss.php');
require_once('include/header.php');
require_once('include/menu.php');
require_once('config.php');
?>

<div class="container">
    <div class="box">
        <div class="box-heading">BẢNG QUẢN TRỊ</div>
        <div class="box-content">
            <?php
            if (isset($_GET['del'])) {
                if ($_GET['kq']) {
                    echo "<font style='color:blue'>Đã xóa đơn hàng thành công!</font>";
                } else {
                    echo "<font style='color:red'>Không thể xóa đơn hàng!</font>";
                }
            }
            $pdo = $conn->prepare('SELECT datab_order.*, SUM(order_quantity) as soluongmon FROM datab_order JOIN datab_order_product ON datab_order.order_id=datab_order_product.order_id WHERE order_status < 2 GROUP BY datab_order.order_id');
            $pdo->execute();
            ?>
            <form>
                <table class="list">
                    <tr bgcolor="#EFEFEF">
                        <th class="image">Đơn hàng</th>
                        <th class="name">Thực khách</th>
                        <th class="quantity">Số xuất ăn</th>
                        <th class="quantity">Thời gian đặt</th>
                        <th class="quantity">Trạng thái</th>
                        <th class="name">Thao tác</th>
                        <th class="name">Chuyển trạng thái</th>
                    </tr>
                    <?php
                    if ($pdo->rowCount()) {
                        $data = $pdo->fetchAll();
                        foreach ($data as $row) {
                            ?>
                            <tr>
                                <td class="image">#<?php echo $row['order_id']; ?></td>
                                <td class="name"><?php echo $row['customer_name']; ?></td>
                                <td class="quantity"><?php echo $row['soluongmon']; ?></td>
                                <td class="quantity"><?php echo $row['order_time']; ?></td>
                                <td class="quantity"><?php echo ($row['order_status'] == 0) ? "<font color='red'>Chờ xử lý</font>" : "Đang xử lý"; ?></td>
                                <td class="action">
                                    <a class='ajax' href="editorder.php?order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>">[Xem]</a>
                                    <a href='javascript:void(0);' onclick= onDel("delorder.php?action=del&order_id=<?php echo $row['order_id'] . "&redirect=controlpanel&token=" . $_SESSION['token']; ?>")>[Xóa]</a>
                                    <a href="export.php?order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>">[Xuất hóa đơn]</a>
                                </td>
                                <td class="action">
                                    <a href="staorder.php?action=edit&status=1&order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>">[Đang xử lý]</a>
                                    <a href="staorder.php?action=edit&status=2&order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>">[Hoàn thành]</a>
                                </td>
                            </tr>    
                            <?php
                        }
                    }
                    ?>
                </table>
            </form>
        </div>
    </div>    
</div>
<?php
require_once('include/footer.php');
?>
 
